package com.metadata_system.ai.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.metadata_system.common.db.entity.Metadata;
import lombok.*;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@AllArgsConstructor
@NoArgsConstructor
@Data
@Builder
public class MetadataResponse {
    private Integer id;
    private String name;
    private String shortName;
    private Integer dataTotal;
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createdTime;
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updatedTime;

    public static MetadataResponse fromEntity(Metadata metadata){
        return MetadataResponse.builder()
                .id(metadata.getId())
                .name(metadata.getName())
                .shortName(metadata.getShortName())
                .dataTotal(metadata.getDataTotal())
                .createdTime(metadata.getCreatedTime())
                .updatedTime(metadata.getUpdatedTime())
                .build();
    }

    public static List<MetadataResponse> fromEntity(List<Metadata> list){
        return list.stream().map(MetadataResponse::fromEntity).collect(Collectors.toList());
    }
}
